package com.tutu.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class RabbitMQSender {

    private final RabbitTemplate rabbitTemplate;

    @Autowired
    public RabbitMQSender(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    /**
     * 发送消息到 dataExchange
     *
     * @param routingKey 路由键
     * @param message    消息内容
     */
    public void sendToDataExchange(String routingKey, Object message) {
        rabbitTemplate.convertAndSend("dataExchange", routingKey, message);
        log.info("Sent to dataExchange: " + message);
    }

    /**
     * 发送消息到 msgExchange
     *
     * @param routingKey 路由键
     * @param message    消息内容
     */
    public void sendToMsgExchange(String routingKey, Object message) {
        rabbitTemplate.convertAndSend("msgExchange", routingKey, message);
        log.info("Sent to msgExchange: " + message);
    }
}